package cn.jaye.fabric.application;

import cn.jaye.fabric.application.command.GuessCommand;
import cn.jaye.fabric.application.command.RegistCommand;
import cn.jaye.fabric.application.command.TestCommand;
import cn.jaye.fabric.common.constant.Global;
import cn.jaye.fabric.domain.model.Guess;
import cn.jaye.fabric.domain.model.User;
import cn.jaye.fabric.domain.service.BlockChainService;
import cn.jaye.fabric.domain.service.RestTemplateService;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Jaye
 * @create 2018-05-31 15:20
 */
@Service
public class TestApplicationService {

    @Autowired
    private AuthApplicationService authApplicationService;

    @Autowired
    private GuessApplicationService guessApplicationService;

    public void registUser() throws InterruptedException {
        int count = 0;
        for (int i = 0; i < 10; i++) {
            String userNum = String.valueOf(i + 1);
            String username = "user-" + userNum;
            RegistCommand registCommand = new RegistCommand();
            registCommand.setUsername(username);
//            String password = authApplicationService.register(registCommand);
//            if (StringUtils.isNotBlank(password)) {
//                count++;
//                System.out.println("success regist user :" + userNum);
//            }
        }
        System.out.println("regist user count: " + String.valueOf(count));
    }

    public void guessGame() {
        int count = 0;
        int flag = 10;
        for (int i = 0; i < flag; i++) {
            String userNum = String.valueOf(i + 1);
            String username = "user-" + userNum;
//            guessApplicationService.guess(getUser(username), getGuessCommand(flag));
        }
    }

    private User getUser(String name) {
        User user = new User();
        user.setUserName(name);
        return user;
    }

    private GuessCommand getGuessCommand(int count) {
        GuessCommand guessCommand = new GuessCommand();
        List<Guess> guessList = new ArrayList<>();
        for (int i = 0; i < count; i++) {
            Guess guess = new Guess();
            guess.setMatchId("m" + String.valueOf(i + 1));
            if (i < 5) {
                guess.setHostScore(i + 1);
                guess.setGuestScore(6 - i);
            } else {
                guess.setHostScore(i - 5);
                guess.setGuestScore(1);
            }
            guessList.add(guess);
        }
        guessCommand.setMatchs(guessList);
        return guessCommand;
    }
}
